#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
static int sum(int value);
struct inout {
    int value;
    int result;
};
bool isdigital(const char* str)
{
    while(*str)
    {
        if(!(*str <= '9' && *str >= '0'))
        {
            return false;
        }
        str++;
    }
    return true;
}
int main(int argc, char* argv[])
{
    struct inout *io = (struct inout*)malloc(sizeof(struct inout));
    if(io == NULL)
    {
        printf("malloc error\n");
        return -1;
    }
    if(argc != 2)
    {
        printf("error\n\tusage app val");
        return -1;
    }
    if(!isdigital(argv[1]))
    {
        printf("您输入不是数字，请重新输入\n");
        return -1;
    }
    int value = atoi(argv[1]);
    io->value = value;
    io->result = sum(io->value);
    printf("您输入的值为:%d, 累加结果为%d\n", io->value, io->result);
    free(io);
    return 0;
}
static int sum(int value)
{
    int count = 0;
    while(value > 0)
    {
        count += value;
        value--;
    }
    return count;
}
